﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Windows;
using System.Windows.Input;
// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://wpfimageviewer.codeplex.com
using BrainTechLLC;
using BrainTechLLC.FilterExtensions;
using ImageAppDataModels;
using ImageAppViewModels;


namespace WpfImageDuplicates
{    
    public partial class ImageDeletedCommand : RoutedCommand, ICommand
    {
        public void Execute(FileImageViewModel vm)
        {
            Window1.MainWindow.CollectionViews.ForEach(o=>o.FileImageCollectionViewModel.RemoveByFileName(vm.FileName));

            if (Window1.MainWindow._FullViewerHandler.IsLoaded &&
                Window1.MainWindow._FullViewerHandler.Handler.IsShowing &&
                Window1.MainWindow._FullViewerHandler.Handler.ImageViewModel != null &&
                Window1.MainWindow._FullViewerHandler.Handler.ImageViewModel.FileName.Equals(vm.FileName))
            {
                Window1.MainWindow._FullViewerHandler.Handler.OnWantNextImage();
            }

            if (Window1.MainWindow._CompareMultiple.IsLoaded)
            {
                ObservableCollection<FileImageViewModel> objs = Window1.MainWindow._CompareMultiple.Handler.CompareWindowFileImageViewModels;
                if (objs != null)
                {
                    objs.RemoveAll(true, (fivm) => fivm.FileName.Equals(vm.FileName));
                }

                objs = Window1.MainWindow._CompareMultiple.Handler.CompareWindowAskFileImageViewModels;

                if (objs != null)
                {
                    objs.RemoveAll(true, (fivm) => fivm.FileName.Equals(vm.FileName));
                }
            }
        }
    }
}
